local getmetatable = getmetatable
local setmetatable = setmetatable
local module = module
local require = require
local type = type
local error = error
local tonumber = tonumber
local print = print
local string = string

module('eg.ArithmeticColumnFixture')
_VERSION='0.1'

local ColumnFixture = require('fit.ColumnFixture')

local function plus(self)
    self.x = tonumber(self.x)
    self.y = tonumber(self.y)

    return self.x + self.y
end

local function minus(self)
    self.x = tonumber(self.x)
    self.y = tonumber(self.y)

    return self.x - self.y
end

local function times(self)
    self.x = tonumber(self.x)
    self.y = tonumber(self.y)

    return self.x * self.y
end

local function divide(self)
    self.x = tonumber(self.x)
    self.y = tonumber(self.y)

    -- Integer division
    if (self.y == 0) then
        error("Error: Divide by 0")
    end

    answ = self.x / self.y
    return string.format("%d", answ)
end

local function floating(self)
    self.x = tonumber(self.x)
    self.y = tonumber(self.y)

    answ = self.x / self.y
    return string.format("%.7f", answ)
end

function __call()
    local aArithmeticColumnFixture = ColumnFixture()

    aArithmeticColumnFixture.x = 0
    aArithmeticColumnFixture.y = 0
    aArithmeticColumnFixture.plus = plus
    aArithmeticColumnFixture.minus = minus
    aArithmeticColumnFixture.times = times
    aArithmeticColumnFixture.divide = divide
    aArithmeticColumnFixture.floating = floating

    return aArithmeticColumnFixture
end

setmetatable(_M, _M)
